package com.leyou.common.advice;

import com.leyou.common.exception.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

//扫描所有的controller中的所有方法，异常抛出后通知
@ControllerAdvice //给所有的controller加了try
public class ControllerExceptionAdvice {

    @ExceptionHandler(LyException.class) //相当于catch
    public ResponseEntity<String> handlerException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }
}